<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<jsp:include page="header.jsp" />
<f:view>

	<h:form>
		<h:panelGroup layout="block" styleClass="t">
			<h:panelGroup layout="block" styleClass="b">
				<h:panelGroup layout="block" styleClass="l">
					<h:panelGroup layout="block" styleClass="r">
						<h:panelGroup layout="block" styleClass="bl">
							<h:panelGroup layout="block" styleClass="br">
								<h:panelGroup layout="block" styleClass="tl">
									<h:panelGroup layout="block" styleClass="tr">

										<h:panelGrid columns="1" cellspacing="0" cellpadding="5"
											border="0" styleClass="formtable" captionClass="mainTitle">
											<f:facet name="caption">
												<h:panelGroup>
													<h:panelGroup layout="block">
														<h:outputText value="Create customer"
															rendered="#{customerEditBean.customerId == 0}"></h:outputText>
														<h:outputText value="Edit customer"
															rendered="#{customerEditBean.customerId > 0}"></h:outputText>
													</h:panelGroup>
												</h:panelGroup>
											</f:facet>
											<h:panelGroup>
												<b><h:outputText value="Name:"></h:outputText> </b>
												<h:message for="customerName" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="customerName"
													value="#{customerEditBean.customer.name}" required="true"
													requiredMessage="Name is required" label="Name"
													styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>


											<h:panelGroup>
												<b><h:outputText value="Address:"></h:outputText> </b>
												<h:message for="customerAddress" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="customerAddress"
													value="#{customerEditBean.customer.address}"
													required="true" requiredMessage="Address is required"
													label="Address" styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>


											<h:panelGroup>
												<b><h:outputText value="Bank:"></h:outputText> </b>
												<h:message for="customerBank" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="customerBank"
													value="#{customerEditBean.customer.bank}" required="true"
													requiredMessage="Bank is required" label="Bank"
													styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>

											<h:panelGroup>
												<b><h:outputText value="BankAccount:"></h:outputText> </b>
												<h:message for="customerBankAccount" showSummary="true"
													showDetail="false" errorClass="errorMsg" />
												<br />
												<h:inputText id="customerBankAccount"
													value="#{customerEditBean.customer.bankAccount}"
													required="true" requiredMessage="BankAccount is required"
													label="BankAccount" styleClass="coolinp">
												</h:inputText>
											</h:panelGroup>



											<h:panelGroup>
												<h:inputHidden value="#{customerEditBean.customerId}" />
												<input type="hidden"
													value="<%=request
																	.getParameter("customerId") != null ? Integer
																	.parseInt(request
																			.getParameter("customerId"))
																	: 0%>"
													name="customerId" />
												<h:commandButton action="#{customerEditBean.saveCustomer}"
													value="Save" accesskey="s" styleClass="frmbutton">
												</h:commandButton>
												<h:outputText value="&nbsp;" escape="false"></h:outputText>
												<h:commandButton action="#{customerEditBean.cancel}"
													value="Cancel" accesskey="c" immediate="true"
													styleClass="frmbutton">
												</h:commandButton>
												<h:outputText value="&nbsp;" escape="false"></h:outputText>
												<h:commandButton action="#{customerEditBean.deleteCustomer}"
													value="Delete" accesskey="d" immediate="true"
													styleClass="frmbutton"
													rendered="#{customerEditBean.customerId > 0}"
													onclick="if(!confirm('Are you sure you want to delete this customer?'))return false;">
												</h:commandButton>
											</h:panelGroup>
										</h:panelGrid>


									</h:panelGroup>
								</h:panelGroup>
							</h:panelGroup>
						</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>
			</h:panelGroup>
		</h:panelGroup>
	</h:form>
	<h:form rendered="#{customerEditBean.customerId > 0}">
		<input type="hidden"
			value="<%=request.getParameter("customerId") != null ? Integer
							.parseInt(request.getParameter("customerId")) : 0%>"
			name="customerId" />
		<h:panelGroup layout="block" styleClass="t">
			<h:panelGroup layout="block" styleClass="b">
				<h:panelGroup layout="block" styleClass="l">
					<h:panelGroup layout="block" styleClass="r">
						<h:panelGroup layout="block" styleClass="bl">
							<h:panelGroup layout="block" styleClass="br">
								<h:panelGroup layout="block" styleClass="tl">
									<h:panelGroup layout="block" styleClass="tr">

										<h:panelGrid columns="1" styleClass="gridtable"
											cellspacing="0" cellpadding="5" border="0"
											rendered="#{empty customerEditBean.customerSubscriptions}"
											captionClass="gridtools">
											<f:facet name="caption">
												<h:panelGroup>
													<h:panelGroup layout="block">
														<h:outputText value="Subscriptions"></h:outputText>
													</h:panelGroup>
													<h:outputLink value="subscription_edit.jsp">
														<f:param name="customerId"
															value="#{customerEditBean.customerId}" />
														<h:outputText value="New Subscription" />
													</h:outputLink>

												</h:panelGroup>
											</f:facet>
											<h:outputText value="No records to display"
												styleClass="noRecordsMessage" />
										</h:panelGrid>

										<h:dataTable styleClass="gridtable" cellspacing="0"
											cellpadding="5" border="0"
											value="#{customerEditBean.customerSubscriptions}"
											var="subscription"
											rendered="#{not empty customerEditBean.customerSubscriptions}"
											rowClasses="white_row,color_row"
											columnClasses=",,,,,,lastColumn" captionClass="gridtools">
											<f:facet name="caption">
												<h:panelGroup>
													<h:panelGroup layout="block">
														<h:outputText value="Subscriptions"></h:outputText>
													</h:panelGroup>
													<h:outputLink value="subscription_edit.jsp">
														<f:param name="customerId"
															value="#{customerEditBean.customerId}" />
														<h:outputText value="New Subscription" />
													</h:outputLink>

												</h:panelGroup>
											</f:facet>

											<h:column>
												<f:facet name="header">
													<h:outputText value="Id"></h:outputText>
												</f:facet>
												<h:outputText value="#{subscription.id}" />
											</h:column>
											<h:column>
												<f:facet name="header">
													<h:outputText value="Start date"></h:outputText>
												</f:facet>
												<h:outputText value="#{subscription.startDate}">
													<f:convertDateTime pattern="dd-MM-yyyy" type="date" />
												</h:outputText>
											</h:column>
											<h:column>
												<f:facet name="header">
													<h:outputText value="Duration"></h:outputText>
												</f:facet>
												<h:outputText value="#{subscription.duration}" />
												<h:outputText value=" months"></h:outputText>
											</h:column>
											<h:column>
												<f:facet name="header">
													<h:outputText value="End date"></h:outputText>
												</f:facet>
												<h:outputText value="#{subscription.endDate}">
													<f:convertDateTime pattern="dd-MM-yyyy" type="date" />
												</h:outputText>
											</h:column>
											<h:column>
												<f:facet name="header">
													<h:outputText value="Supplier"></h:outputText>
												</f:facet>
												<h:outputLink target="_blank" value="supplier_edit.jsp">
													<f:param name="supplierId"
														value="#{subscription.supplier.id}"></f:param>
													<f:param name="action" value="edit" />
													<h:outputText value="#{subscription.supplier.name}" />
												</h:outputLink>
											</h:column>
											<h:column>
												<f:facet name="header">

													<h:outputText value="Magazine"></h:outputText>
												</f:facet>
												<h:outputLink target="_blank" value="magazine_edit.jsp">
													<f:param name="magazineId"
														value="#{subscription.magazine.id}"></f:param>
													<f:param name="action" value="edit" />
													<h:outputText value="#{subscription.magazine.name}" />
												</h:outputLink>
											</h:column>
											<h:column>

												<h:outputLink value="subscription_edit.jsp">
													<f:param name="subscriptionId" value="#{subscription.id}" />
													<f:param name="customerId"
														value="#{customerEditBean.customerId}" />
													<f:param name="action" value="edit" />
													<h:graphicImage alt="Edit Subscription"
														title="Edit Subscription" value="./res/img/edit.gif"></h:graphicImage>
												</h:outputLink>
												<h:outputText value=" "></h:outputText>
												<h:commandLink
													action="#{customerEditBean.deleteSubscription}"
													onclick="if(!confirm('Are you sure you want to delete this subscription?'))return false;">
													<f:setPropertyActionListener
														target="#{customerEditBean.subscription}"
														value="#{subscription}" />
													<h:graphicImage alt="Delete Subscription"
														title="Delete Subscription" value="./res/img/trash2.gif"></h:graphicImage>
												</h:commandLink>
											</h:column>

										</h:dataTable>



									</h:panelGroup>
								</h:panelGroup>
							</h:panelGroup>
						</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>
			</h:panelGroup>
		</h:panelGroup>
	</h:form>
</f:view>

<jsp:include page="footer.jsp" />
